home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / PowerPlant / NeoAccess / CAMReminderDoc.cp < prev    next >
Encoding:
Text File  |  1995-10-05  |  4.6 KB  |  222 lines  |  [TEXT/MMCC]

  1. // CAMReminderDoc.cp -- Document methods
  2. // Created 10/5/95 8:02 PM by AppMaker
  3.  
  4. #include "CAMReminderDoc.h"
  5.  
  6. #include "CAMReminderData.h"
  7. #include "CMainWindow.h"
  8. #include "CmdCodes.h"
  9. #include "CAdd.h"
  10.  
  11. #include <LFile.h>
  12. #include <LPlaceHolder.h>
  13. #include <LPrintout.h>
  14. #include <LWindow.h>
  15. #include <UWindows.h>
  16. #include <String_Utils.h>
  17.  
  18. const ResIDT    prto_PrintView        = 201;
  19. const ResIDT    STRx_Untitled        = 128;
  20.  
  21. // ---------------------------------------------------------------------------
  22. //        • CAMReminderDoc
  23. // ---------------------------------------------------------------------------
  24.  
  25. CAMReminderDoc::CAMReminderDoc    (const Boolean    inPrintable,
  26.                                  const Boolean    inNewDatabase,
  27.                                  const Boolean    inRemote)
  28.         : CNeoDocRoot (kSignature, kFileType, inPrintable, inNewDatabase)
  29. {
  30.     mData = new CAMReminderData (this, (CNeoDatabasePP *)mFile);
  31. }
  32.  
  33. // ---------------------------------------------------------------------------
  34. //        • ~CAMReminderDoc
  35. // ---------------------------------------------------------------------------
  36. //    Destructor
  37. //
  38.  
  39. CAMReminderDoc::~CAMReminderDoc()
  40. {
  41.     delete mData;
  42. }
  43.  
  44. //----------
  45. void
  46. CAMReminderDoc::newDatabase ()
  47. {
  48.     FSSpec        spec;
  49.  
  50.     inherited::newDatabase();
  51.  
  52.     // Set the default name which appears in the get file dialog.
  53.     spec.vRefNum = 0;
  54.     spec.parID = 0;
  55.     NeoStringCopy ("\pAMReminder", spec.name);
  56.     ((CNeoDatabasePP *)mFile)->setFileSpec (spec);
  57.  
  58.     NameNewDoc();    // Set name of untitled window
  59. }
  60.  
  61. //----------
  62. void
  63. CAMReminderDoc::buildWindow()
  64. {
  65.     mMainWindow = CMainWindow::CreateMainWindow(this, mData);
  66.  
  67.     mWindow = mMainWindow;
  68. }
  69.  
  70. // ---------------------------------------------------------------------------
  71. //        • NameNewDoc
  72. // ---------------------------------------------------------------------------
  73. //    Name a new, untitled document window
  74. //
  75. //    Untitled windows start with "untitled", then "untitled 1",
  76. //    "untitled 2", etc. Old numbers are reused, so there won't be
  77. //    gaps in the numbering.
  78. //
  79. //    This routine uses a STR# resource to store the "untitled" string,
  80. //    which can be localized to different languages. The first string
  81. //    is "untitled" and the second is "untitled " (trailing space),
  82. //    which is used when appending a number to the name.
  83.  
  84. void
  85. CAMReminderDoc::NameNewDoc()
  86. {
  87.         // Start with the default name("untitled")
  88.     Str255    name;
  89.     ::GetIndString(name, STRx_Untitled, 1);
  90.  
  91.     long    num = 0;
  92.     while (UWindows::FindNamedWindow(name) != nil) {
  93.  
  94.             // An existing window has the current name
  95.             // Increment counter and try again
  96.  
  97.         ::GetIndString(name, STRx_Untitled, 2);
  98.         num++;
  99.         Str15    numStr;
  100.         ::NumToString(num, numStr);
  101.         ConcatPStr(name, numStr);
  102.     }
  103.  
  104.     mWindow->SetDescriptor(name);        // Finally, set window title
  105. }
  106.  
  107.  
  108. // ---------------------------------------------------------------------------
  109. //        • DoPrint
  110. // ---------------------------------------------------------------------------
  111. //    Print the contents of the Document
  112.  
  113. void
  114. CAMReminderDoc::DoPrint()
  115. {
  116.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  117.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  118.                                     thePrintout->FindPaneByID('TBox');
  119. //!    textPlace->InstallOccupant(mTextView, atNone);
  120.  
  121.  
  122.     thePrintout->DoPrintJob();
  123.     delete thePrintout;
  124. }
  125.  
  126. //----------
  127. void
  128. CAMReminderDoc::DoAddReminder ()
  129. {
  130. CAdd*    dialog = CAdd::CreateAdd(this);
  131. }
  132.  
  133. //----------
  134. void
  135. CAMReminderDoc::DoEditReminder ()
  136. {
  137. CAdd*    dialog = CAdd::CreateAdd(this);
  138. }
  139.  
  140. //----------
  141. void
  142. CAMReminderDoc::DoDeleteReminder ()
  143. {
  144. }
  145.  
  146. //----------
  147. void
  148. CAMReminderDoc::ObeyAdd    (void*    ioParam)
  149. {
  150. }
  151.  
  152. //----------
  153. Boolean
  154. CAMReminderDoc::ObeyCommand(
  155.     CommandT    inCommand,
  156.     void        *ioParam)
  157. {
  158.     Boolean        cmdHandled = true;
  159.  
  160.     switch (inCommand) {
  161.  
  162.     // +++ Add cases here for the commands you handle
  163.     //        Remember to add same cases to FindCommandStatus below
  164.     //        to enable/disable the menu items for the commands
  165.  
  166.  
  167.     case cmdAddReminder:
  168.         DoAddReminder ();
  169.         break;
  170.  
  171.     case cmdEditReminder:
  172.         DoEditReminder ();
  173.         break;
  174.  
  175.     case cmdDeleteReminder:
  176.         DoDeleteReminder ();
  177.         break;
  178.  
  179.     case cmd_Add:
  180.         ObeyAdd    (ioParam);
  181.         break;
  182.  
  183.     default:
  184.             cmdHandled = CNeoDocNative::ObeyCommand(inCommand, ioParam);
  185.         break;
  186.     }
  187.  
  188.     return cmdHandled;
  189. }
  190.  
  191. //----------
  192. void
  193. CAMReminderDoc::FindCommandStatus(
  194.     CommandT    inCommand,
  195.     Boolean        &outEnabled,
  196.     Boolean        &outUsesMark,
  197.     Char16        &outMark,
  198.     Str255        outName)
  199. {
  200.     outUsesMark = false;
  201.  
  202.     switch (inCommand) {
  203.  
  204.     // +++ Add cases here for the commands you handle
  205.  
  206.     case cmdAddReminder:
  207.         outEnabled = true;
  208.         break;
  209.     case cmdEditReminder:
  210.         outEnabled = true;
  211.         break;
  212.     case cmdDeleteReminder:
  213.         outEnabled = true;
  214.         break;
  215.  
  216.     default:
  217.             CNeoDocNative::FindCommandStatus(inCommand, outEnabled,
  218.                                             outUsesMark, outMark, outName);
  219.         break;
  220.     }
  221. }
  222.